import QtQuick 1.0

MyPage {
    id: messagesPage
    objectName: "messagesPage"

    /********************************************************************************/
    colorPage: "white"


    property string _selectedItem_jid
    property string _selectedItem_pass
    property bool _selectedItem_default

    Component {
        id: componentAccountItem
        Rectangle {
            id: wrapper
            clip: true
            width: listViewAccounts.width
            height: 90
            color: "white"
            Image {
                id: imgAcc
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 10
                source: accIcon
            }
            Text {
                id: txtAcc
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: imgAcc.right
                anchors.leftMargin: 10
                text: accJid
                font.pixelSize: 36
            }
            Image {
                id: imgDefualt
                source: "qrc:/qml/images/bar_ok.png"
                anchors.right: parent.right; anchors.rightMargin: 5
                anchors.verticalCenter: parent.verticalCenter
                //anchors.top: parent.top; anchors.topMargin: 5
                height: 40
                width: 40
                smooth: true
                visible: accDefault
            }

            states: State {
                name: "Current"
                when: wrapper.ListView.isCurrentItem
                PropertyChanges { target: wrapper; color: "lightblue" }
            }

            transitions: Transition {
                //NumberAnimation { properties: "position"; duration: 300 }
            }

            MouseArea {
                id: maAccItem
                anchors.fill: parent
                onDoubleClicked: {
                    wrapper.ListView.view.currentIndex = index
                    dlgAccOptions._edit_jid = accJid
                    dlgAccOptions._edit_pass = accPasswd
                    dlgAccOptions._edit_default = accDefault
                    dlgAccOptions.state = "visible"
                    console.log("acc edit: " + dlgAccOptions._edit_jid +" " + dlgAccOptions._edit_pass + " " + dlgAccOptions._edit_default )
                }
                onClicked: {
                    wrapper.ListView.view.currentIndex = index
                }
            }

        }
    }

    ListView {
        id: listViewAccounts
        anchors.top: parent.top
        anchors.bottom: toolBar.top
        anchors.left: parent.left
        anchors.right: parent.right
        clip: true
        delegate: componentAccountItem
        model: cppListOfAccounts
    }

    Component.onCompleted: { cppMeegIMSettings.initListOfAccounts() }


    /********************************( Toolbar )************************************/

    ToolBar {
        id: toolBar

        ToolButton {
            id: toolBarButtonRoster
            icon: "qrc:/qml/images/bar_roster.png"
            anchors.left: parent.left
            anchors.leftMargin: (0.5*(parent.width/4) - 0.5*toolBarButtonRoster.width)
            onClicked: {
                messagesPage.closePage( "qrc:/qml/RosterPage.qml" )
            }
            pauseAnim: 500
        }
        /*
        ToolButton {
            id: toolBarButtonChats
            icon: "qrc:/qml/images/bar_open_chats.png"
            anchors.left: parent.left
            anchors.leftMargin: (1.5*(parent.width/4) - 0.5*toolBarButtonChats.width)
            onClicked: {
                messagesPage.closePage( "qrc:/qml/ChatsPage.qml" )
            }
            pauseAnim: 600
        }
        ToolButton {
            id: toolBarButtonSmiles
            icon: "qrc:/qml/images/bar_smiles.png"
            anchors.left: parent.left
            anchors.leftMargin: (2.5*(parent.width/4) - 0.5*toolBarButtonSmiles.width)
            onClicked: {
            }
            pauseAnim: 700
        }
        */
        ToolButton {
            id: toolBarButtonOptions
            icon: "qrc:/qml/images/bar_add.png"
            anchors.left: parent.left
            anchors.leftMargin: (3.5*(parent.width/4) - 0.5*toolBarButtonOptions.width)
            /*onClicked: {
                dlgAccOptions._edit_jid = ""
                dlgAccOptions._edit_pass = ""
                dlgAccOptions._edit_default = false
                dlgAccOptions.state = "visible"
            }*/
            onClicked: {
                messagesPage.closePage( "qrc:/qml/AccountAddPage.qml" )
            }

            pauseAnim: 800
        }
    }


    /*********************************************************************/

    DialogAccountOptions {
        id: dlgAccOptions
    }

    /*********************************************************************/
}
